package com.wenshi.app.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.view.ViewStub;


import com.wenshi.view.IKeyValue;
import com.wenshi.view.WsViewTools;



/**
 *该类适用于普通的布局使用 但整体界面可以刷新更新数据的， 直接extends该类即可
 */
public abstract class WsRefreshActivity extends WsBaseActivity implements SwipeRefreshLayout.OnRefreshListener {
    private Context mContext;
    private SwipeRefreshLayout sw_downrefresh_layout;

    private boolean isNoticeSueper = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
    }


    /**
     * 绑定视图和数据的方法
     * 参数HashMap<String, String> data，int layoutid
     *
     *
     *
     */
    public void renderView(IKeyValue data, int layoutid) {
        setContentView(layoutid);
        super.renderView(data);

    }
    protected  void  stopRefreshing()
    {
        sw_downrefresh_layout.setRefreshing(false);
    }

    public void setContentView(int layoutid) {
        if (!isNoticeSueper) {
            getWsWiewDelegate().setContentView(WsViewTools.getResource(this,"wsview_activity_pub_wsdownrefresh","layout"));

//            sw_downrefresh_layout = (SwipeRefreshLayout) findViewById(R.id.base_downrefresh_layout);
            sw_downrefresh_layout = (SwipeRefreshLayout) findViewById(WsViewTools.getResource(this,"base_downrefresh_layout","id"));
            sw_downrefresh_layout.setColorSchemeResources(
                    android.R.color.holo_blue_light,
                    android.R.color.holo_red_light,
                    android.R.color.holo_orange_light,
                    android.R.color.holo_green_light);
            sw_downrefresh_layout.setOnRefreshListener(this);
            isNoticeSueper = true;
        }


//        ViewStub contentview = (ViewStub) sw_downrefresh_layout.findViewById(R.id.vs_downrefresh_layout);
        ViewStub contentview = (ViewStub) sw_downrefresh_layout.findViewById(WsViewTools.getResource(this,"vs_downrefresh_layout","id"));
     contentview.setLayoutResource(layoutid);
     //   contentview.inflate();
      contentview.setVisibility(View.VISIBLE);

    }


}
